package com.ztgf.shopping.api.cms.shop;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.ztgf.common.constant.Result;
import com.ztgf.common.enums.CodeEnum;
import com.ztgf.shopping.models.vo.shop.ShopBrandRelationVO;
import com.ztgf.shopping.models.vo.shop.ShopInfoBrandVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import com.ztgf.shopping.models.service.shop.IShopBrandRelationService;
import com.ztgf.shopping.models.bo.shop.ShopBrandRelationBO;
import com.ztgf.shopping.models.dto.shop.ShopBrandRelationDTO;

/**
 * 店铺品牌关系表控制器
 *
 * @author zhanghualang
 * @Date 2020-05-28 14:43:46
 */

@RestController
@RequestMapping("/cms/shopBrandRelation")
@Slf4j
@Api(value = "ShopBrandRelationController",tags = "店铺品牌关系表接口")
public class ShopBrandRelationController {

    @DubboReference
    private IShopBrandRelationService shopBrandRelationService;

    @PostMapping("/get")
    @ApiOperation(value = "根据id查找",notes = "根据id查找")
    @ApiImplicitParam(name = "id",value = "id",required = true,paramType = "query", dataType = "Long")
    public Result<ShopBrandRelationDTO> get(@RequestParam("id") Long id){
        if(id == null){
            return new Result<>(CodeEnum.FAIL_100002 );
        }

        ShopBrandRelationDTO dto = shopBrandRelationService.selectById(id);

        return new Result<>(dto);
    }

    @ApiOperation(value = "根据品牌ID查询出所有店铺列表",notes = "根据品牌ID查询出所有店铺列表")
    @PostMapping("/queryShopPageList")
    public Result<Page<ShopInfoBrandVO>> queryFranchiseShopPageList(ShopBrandRelationBO bo){
        Page<ShopInfoBrandVO> page = new Page<>(bo.getPageNo(), bo.getPageSize());
        page = shopBrandRelationService.queryShopPageList(page, bo);

        return new Result<>(page);
    }

    @ApiOperation(value = "店铺品牌关系表列表",notes = "店铺品牌关系表列表")
    @PostMapping("/queryPageList")
    public Result<Page<ShopBrandRelationDTO>> queryPageList(ShopBrandRelationBO bo){
        Wrapper<ShopBrandRelationDTO> wrapper = new EntityWrapper<>();

        Page<ShopBrandRelationDTO> page = new Page<>(bo.getPageNo(), bo.getPageSize());
        page = shopBrandRelationService.selectPage(page, wrapper);

        return new Result<>(page);
    }

    @ApiOperation(value = "根据店铺ID查询店铺下所有品牌列表",notes = "根据店铺ID查询店铺下所有品牌列表")
    @PostMapping("/queryVOList")
    @ApiImplicitParam(name = "id",value = "id",required = true,paramType = "query", dataType = "Long")
    public Result<List<ShopBrandRelationVO>> queryPageList(@RequestParam("id") Long id){
        if(id == null){
            return new Result<>(CodeEnum.FAIL_100002 );
        }
        List<ShopBrandRelationVO> vos = shopBrandRelationService.queryVOList(id);

        return new Result<>(vos);
    }
}
